package com.enation.app.javashop.core.client.fallback.payment;

import com.enation.app.javashop.core.client.feignimpl.payment.RefundClientFeignImpl;
import com.enation.app.javashop.core.handler.BaseFallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 *  退款 client熔断  factory
 * @author kingapex
 * @version 1.0
 * @data 2022/5/28 14:59
 **/
@Component
public class RefundClientFallbackFactory extends BaseFallbackFactory<RefundClientFeignImpl> {
    @Override
    protected RefundClientFeignImpl fallback() {
        return new RefundClientFallback();
    }

    /**
     * 退款 client熔断
     *
     * @author fk
     * @version v7.0
     * @date 20/3/11 下午3:27
     * @since v7.2.1
     */
    @Component
    public static class RefundClientFallback implements RefundClientFeignImpl {

        private final Logger logger = LoggerFactory.getLogger(getClass());

        @Override
        public Map originRefund(String returnTradeNo, String refundSn, Double refundPrice, String subType) {
            logger.debug("原路退回失败，退款单号："+refundSn+",子业务类型："+subType);
            Map<String, Object> result = new HashMap();
            result.put("result",false);
            result.put("fail_reason","原路退回失败，进入了断路器");
            return result;
        }

        @Override
        public String queryRefundStatus(String returnTradeNo, String refundSn, String subType) {
            logger.debug("查询退款失败状态，退款单号："+refundSn+",子业务类型："+subType);
            return null;
        }
    }
}
